#pragma once
#ifndef EPOLLPOLLER_H
#define EPOLLPOLLER_H
#include "Poller.h"
#include <vector>
#include <sys/epoll.h>
#include "TimeStamp.h"
namespace mymuduo {

class Channel;

/*
 * epoll_create
 * epoll_ctl add/mod/del
 * epoll_wait
 * 相当于多路事件分发器
*/

class EpollPoller : public Poller {
public:
    EpollPoller(EventLoop* loop);
    // 覆盖基类抽象方法
    ~EpollPoller() override;
    // epoll_wait 的操作
    TimeStamp poll(int timeoutMs, ChannelList* activeChannels) override;
    // epoll_ctl 的操作
    void updateChannel(Channel *channel) override;
    void removeChannel(Channel *channel) override;

private:
    using EventList = std::vector<epoll_event>;

    // 填写活跃的连接
    void fillActiveChannels(int numEvents, ChannelList *activeChannels) const;
    // 更新 channel 通道
    void update(int operation, Channel* channel);

    // vector 初始化长度
    static const int kInitEventListSize = 16;
    int epollfd_;
    EventList events_;
};

}

#endif